<template>
	<div class="modal" v-show="show">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button class="close" v-on:click="dismiss"><span>&times;</span></button>
					<p class="header-title">提示</p>
				</div>
				<div class="modal-body">
					<p class="text-center">{{ message }}</p>
					<button class="btn-dismiss" v-on:click="dismiss">关闭</button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import {bus} from '../main.js'

export default{
	name: 'alertmodal',
	data() {
		return {
			message: '发生了一个错误',
			show: false
		}
	},
	methods: {
		dismiss: function(){
			this.show = false
		}
	},
	mounted: function(){
		bus.$on('alert', function(message){
			this.message = message
			this.show = true
		}.bind(this))
	}
}
</script>

<style scoped>
body{
  background-color: pink;
  font-family: sans-serif;
}

.modal{
  background-color: rgba(133,133,133,0.3);
  position: fixed;
  top: 0px;
  bottom: 0px;
  left: 0px;
  right: 0px;
  outline: 0;
  z-index: 2000;
  opacity: 1;
  box-sizing: border-box;
}

.modal-dialog{
  margin: 300px auto;
  position: relative;
  width: 300px;
}

.text-center{
  text-align: center;
  clear: both;
}

.modal-content{
  background-color: white;
  border-radius: 6px;
  border: 1px solid gray;
}

.modal-body{
  padding-bottom: 10px;
}

.modal-header{
  padding: 0px;
  border-bottom-color: rgba(1,1,1,0.2);
  border-bottom-style: solid;
  border-bottom-width: 1px;
}

.close{
  float: right;
  font-size: 21px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-weight: bold;
  line-height: 1;
  opacity: .5;
  position: relative;
  top: 8px;
  right: 5px;
}

.header-title{
  position: relative;
  top: 0px;
  right: 100px;
  color: black;
  font-size: 18px;
}

.btn-dismiss{
  position: relative;
  width: 150px;
  height: 30px;
  color: black;
  font-size: 15px;
  background-color: white;
  border: 1px solid gray;
  border-radius: 5px;
  cursor: pointer;
}
</style>